package com.xcc.netty.socket;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author frosty
 * @description client
  * @date 2019-12-30 30:10:17
 */


public class ClientSocket {

    public static void main(String[] args) {
        System.out.println("client start up");
        Socket socket=null;
        OutputStream os=null;
        InputStream is=null;
             Scanner scanner=new Scanner(System.in);
        byte[]  buff=new byte[1024];
         try{
            socket=new Socket(InetAddress.getLocalHost(),8761);
             os=socket.getOutputStream();
               is=socket.getInputStream();
            while (true) {
                int len=0;
                String s=scanner.next();
                os.write(s.getBytes("gbk"));
                if((len=is.read(buff))!=-1){
                    System.out.println(new String(buff,0,len,"gbk"));
                }

            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
